//
// Created by Administrator on 2023/7/27.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int deleteGreatestValue(vector<vector<int>> &grid) {
        // 本质上就是每行排序后，分别取最大值
        auto m = grid.size(), n = grid[0].size();
        for (int i = 0; i < m; ++i) {
            // 每行排序
            sort(grid[i].begin(), grid[i].end());
        }
        int ans = 0;
        // 每一列取最大值
        for (int j = 0; j < n; ++j) {
            int mx = 0;
            for (int i = 0; i < m; ++i) {
                mx = max(mx, grid[i][j]);
            }
            ans += mx;
        }
        return ans;
    }

};


int main() {
    Solution s;
    vector<vector<int>> grid{{1, 2, 4},
                             {3, 3, 1}};
    auto ans = s.deleteGreatestValue(grid);
    cout << ans << endl;
}